package vn.edu.fpt.xml.back.daos;

import org.springframework.stereotype.Repository;
import vn.edu.fpt.xml.back.entities.ChannelEntity;

import javax.persistence.Query;
import java.util.List;

/**
 * Created by hiephn on 2014/04/27.
 */
@Repository
public class ChannelDao extends GenericJpaDao<ChannelEntity> {

    private static final String FROM_CHANNEL_ENTITY = "FROM " + ChannelEntity.class.getName();

    private static final String FIND_BY_TITLE_QUERY = FROM_CHANNEL_ENTITY + " WHERE title = :title";

    public ChannelEntity findByTitle(String title) {
        Query query = entityManager.createQuery(FIND_BY_TITLE_QUERY);
        query.setParameter("title", title);
        return executeSingle(query);
    }

    public List<ChannelEntity> findAll() {
        Query query = entityManager.createQuery(FROM_CHANNEL_ENTITY);
        return executeList(query);
    }

}
